<?php
include_once(dirname(__FILE__).'/../../autoload.php');

/**
 * Description of RegistryTest
 *
 * @author joona
 * @runInSeparateProcess
 */
class Unit_Core_RegistryTest extends Lib_UnitTestcase
{
    public static function setUpBeforeClass()
    {
        require_once('Core/Registry.php');
        Lib_RegistryModifier::returnOriginalApplicationINI();
        Lib_RegistryModifier::backupApplicationINI();
    }

    protected function modifyApplicationIni()
    {
        Lib_RegistryModifier::modifyApplicationINI(
            array(
                'DB_HOST = localhost' => 'DB_HOST = bogushost',
                'DB_USER = sweatshop' => 'DB_USER = bogususer',
                'DB_PASS = sweatshop' => 'DB_PASS = boguspass',
                'DB_NAME = sweatshop' => 'DB_NAME = bogusname'
            )
        );
        Core_Registry::reset();
    }

    public function test_get_modified()
    {
        $this->modifyApplicationIni();
        $expected = array(
            'bogushost','root','','bogusname');
        $actual = array(
            Core_Registry::get('DB_HOST'),
            Core_Registry::get('DB_USER'),
            Core_Registry::get('DB_PASS'),
            Core_Registry::get('DB_NAME')
        );
        $this->assertEquals($expected,$actual);
    }

    public function test_get_all()
    {
        $this->modifyApplicationIni();
        $actual = Core_Registry::get();
        $this->assertArrayHasKey('DB_HOST', $actual);
        $this->assertArrayHasKey('DB_USER', $actual);
        $this->assertArrayHasKey('DB_PASS', $actual);
        $this->assertArrayHasKey('DB_NAME', $actual);
    }

    public static function teardownAfterClass()
    {
        Lib_RegistryModifier::returnOriginalApplicationINI();
        Core_Registry::reset();
    }
}
